package net.uhuijia.vo;

import net.uhuijia.base.BaseCode;

import java.io.Serializable;

public class ResultMapVo<T>  implements Serializable {


    /**
     * 序列化标识
     */
    private static final long serialVersionUID = 4893280118017319089L;
    private String code;
    private String msg;
    private T data;


    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }


    /**
     * Instantiates a new ResultMapVo. default code=200
     */
    public ResultMapVo() {
        this(BaseCode.SUCCESS_ERROR_CODE, BaseCode.SUCCESS_ERROR_MSG);
    }

    /**
     * Instantiates a new ResultMapVo.
     *
     * @param code    the code
     * @param message the message
     */
    ResultMapVo(String code, String message) {
        this(code, message, null);
    }

    /**
     * Instantiates a new ResultMapVo.
     *
     * @param code    the code
     * @param message the message
     * @param result  the result
     */
    ResultMapVo(String code, String message, T result) {
        super();
        this.code(code).message(message).result(result);
    }

    /**
     * Sets the 编号 , 返回自身的引用.
     *
     * @param code the new 编号
     *
     * @return the ResultMapVo
     */
    private ResultMapVo<T> code(String code) {
        this.setCode(code);
        return this;
    }

    /**
     * Sets the 信息 , 返回自身的引用.
     *
     * @param msg the new 信息
     *
     * @return the ResultMapVo
     */
    private ResultMapVo<T> message(String msg) {
        this.setMsg(msg);
        return this;
    }

    /**
     * Sets the 结果数据 , 返回自身的引用.
     *
     * @param data the new 结果数据
     *
     * @return the ResultMapVo
     */
    public ResultMapVo<T> result(T data) {
        this.setData(data);
        return this;
    }


    public static  ResultMapVo<?> ok() {
        return new ResultMapVo<Object>();
    }

    public static <T> ResultMapVo<T> ok(T o) {
        return new ResultMapVo<>(BaseCode.SUCCESS_ERROR_CODE, BaseCode.SUCCESS_ERROR_MSG, o);
    }

    public static  ResultMapVo<?> wrap(String code, String message) {
        return new ResultMapVo<Object>(code, message, null);
    }


}
